/*
 * @Author: “ygnnli” “1585923072@qq.com”
 * @Date: 2024-08-09 15:15:41
 * @LastEditors: “ygnnli” “1585923072@qq.com”
 * @LastEditTime: 2024-08-09 21:20:06
 * @FilePath: /83/Reactor/Main.cc
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include <iostream>
#include <memory>
#include "Log.hpp"
#include "Reactor.hpp"
#include "Listener.hpp"
#include "Connection.hpp"
#include "HandlerConnection.hpp"
#include "PackageParse.hpp"

int main(int argc, char *argv[])
{
    if (argc != 2)
    {
        std::cout << "usage: " << argv[0] << " port" << std::endl;
        return 0;
    }
    uint16_t port = std::stoi(argv[1]);

    EnableScreen();                                               // 开启屏幕输出
    std::unique_ptr<Reactor> react = std::make_unique<Reactor>(); // 创建服务器对象

    HandlerConnection hc(PackageParse::Parse); 

    Listener listener(port,hc); // 负责连接的模块
    // 注册
    react->AddConnection(listener.Sockfd(),
     (EPOLLIN | EPOLLET),
      std::bind(&Listener::Accepter, &listener, std::placeholders::_1)
      ,nullptr, nullptr);

    react->Dispatcher(); // 启动服务器

    return 0;
}